#include "conePlotter.h"
#include <string>
#include <fstream>
#include <curlWrapper.h>
#include <boost\lexical_cast.hpp>

using namespace std;


conePlotter::conePlotter(void)
{
}


conePlotter::~conePlotter(void)
{
}
int conePlotter::getSlotNumber(int x,int y)
{
	map<int,map<int,int> >::iterator x_itr = this->slot_map.find(x);
	map<int,int>::iterator y_itr = x_itr->second.find(y);
	return y_itr->second;
}

void conePlotter::basicConegen()
{
	int node_id = 1700000;
	int max = 10;
	int j = 0;
	std::ofstream opfilepointer;
	/*opfilepointer.open("D:\\RA\\cone_3.gexf",std::ios::app);*/
	//opfilepointer<<"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"<<endl;
	curlWrapper tempCurl;
	tempCurl.setopfilename("vplotevents.rec");
	int slot_number=1;
	bool isUp = false;
	while ( j<=max)
	{
		for ( int i = j ; i<=max;i++)
		{
				/*opfilepointer<<"<node id=\""<<node_id<<"\">"<<endl;
				opfilepointer<<"<viz:position x=\""<<j*1000<<"\" y=\""<<i*1000<<"\"/>"<<endl;
				opfilepointer<<"</node>"<<endl;*/
				map<string,string> node_prop;
				node_prop.insert(pair<string,string>("size","1"));
				node_prop.insert(pair<string,string>("r","0"));
				node_prop.insert(pair<string,string>("g","0"));
				node_prop.insert(pair<string,string>("b","0"));
				node_prop.insert(pair<string,string>("x",boost::lexical_cast<std::string>(j*100+0.1)));
				node_prop.insert(pair<string,string>("y",boost::lexical_cast<std::string>(i*100+0.1)));
				if ( i == j)
					tempCurl.add_node(node_id,node_prop);
				node_id++;
				if ( j!=0)
				{
					map<string,string> node_prop_1;
					node_prop_1.insert(pair<string,string>("size","1"));
					node_prop_1.insert(pair<string,string>("r","0"));
					node_prop_1.insert(pair<string,string>("g","0"));
					node_prop_1.insert(pair<string,string>("b","0"));
					node_prop_1.insert(pair<string,string>("x",boost::lexical_cast<std::string>(-j*100+0.1)));
					node_prop_1.insert(pair<string,string>("y",boost::lexical_cast<std::string>(i*100+0.1)));
					if ( j==i)
						tempCurl.add_node(node_id,node_prop_1);
					node_id++;
					map<int,map<int,int> >::iterator x_itr = this->slot_map.find(j);
					map<int,map<int,int> >::iterator x_itr_1 = this->slot_map.find(-j);

					if ( x_itr == this->slot_map.end())
					{
						map<int,int> temp1;
						if ( isUp)
							temp1.insert(pair<int,int>(i,slot_number));
						else
							temp1.insert(pair<int,int>(max-i+j,slot_number));
						this->slot_map.insert(pair<int,map<int,int> >(j,temp1));
						this->slot_map.insert(pair<int,map<int,int> >(-j,temp1));

						/*this->slot_map.insert(pair<int,map<int,int> >(j,pair<int,int>(i,slot_number)));
						this->slot_map.insert(pair<int,map<int,int> >(-j,pair<int,int>(i,slot_number)));*/
						slot_number++;

					}
					else 
					{
						if ( isUp)
						{
							x_itr->second.insert(pair<int,int>(i,slot_number));
							x_itr_1->second.insert(pair<int,int>(i,slot_number));
						}
						else
						{
							x_itr->second.insert(pair<int,int>(max-i+j,slot_number));
							x_itr_1->second.insert(pair<int,int>(max-i+j,slot_number));
						}

						slot_number++;
					}
				}
			
				/*opfilepointer<<"<node id=\""<<node_id<<"\">"<<endl;
				opfilepointer<<"<viz:position x=\""<<j*1000<<"\" y=\""<<i*1000<<"\"/>"<<endl;
				opfilepointer<<"</node>"<<endl;*/
			
				/*opfilepointer<<"<node id=\""<<node_id<<"\">"<<endl;
				opfilepointer<<"<viz:position x=\""<<-j*1000<<"\" y=\""<<i*1000<<"\"/>"<<endl;
				opfilepointer<<"</node>"<<endl;*/
			
			
		}
		j++;
		isUp = !isUp;
	}
	this->max_slot_no = slot_number;
	
}

